<app-search-bar
  [submitLoading]="tableParams.loading"
  [searchOptions]="searchOptions"
  (onSearch)="queryData($event)"
  (onReset)="resetData($event)"
>
</app-search-bar>

<nz-card class="m-t-2">
  <div class="operation-wrap">
    <button
      nz-button
      nzType="primary"
      class="m-r-8"
      [nzLoading]="exportLoading"
      (click)="exportTable()">
      <i nz-icon nzType="download"></i>
      导出
    </button>
    <button
      nz-button
      nzType="primary"
      nzDanger
      class="m-r-8"
      (click)="showPaymentModal()">
      打款失败
    </button>
    <button nz-button nzType="primary" (click)="subPayment(1)">打款成功</button>
  </div>

  <div class="pagination-wrap-position table-wrap p-t-15">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzBordered
      [nzScroll]="{ x: '1100px' }"
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableParams.loading"
      [nzData]="tableParams.tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableParams.total"
      [nzPageIndex]="tableParams.page"
      [nzPageSize]="tableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
      (nzCurrentPageDataChange)="onCurrentPageDataChange($event)"
    >
      <thead>
        <tr>
          <th
            nzAlign="center"
            nzLeft
            nzWidth="70px"
            [(nzChecked)]="checked"
            [nzIndeterminate]="indeterminate"
            (nzCheckedChange)="onAllChecked($event)"
          ></th>
          <th nzAlign="center" nzWidth="200px" nzLeft>订单编号</th>
          <th nzAlign="center" nzWidth="150px">订单状态</th>
          <th nzAlign="center" nzWidth="120px">退货信息</th>
          <th nzAlign="center" nzWidth="120px">验机状态</th>
          <th nzAlign="center" nzWidth="150px">下单机型</th>
          <th nzAlign="center" nzWidth="150px">预估合计</th>
          <th nzAlign="center" nzWidth="180px">机器编码</th>
          <th nzAlign="center" nzWidth="120px">验机价</th>
          <th nzAlign="center" nzWidth="120px">加价金额</th>
          <th nzAlign="center" nzWidth="120px">下单抽奖</th>
          <th nzAlign="center" nzWidth="150px">验机合计</th>
          <th nzAlign="center" nzWidth="170px">下单时间</th>
          <th nzAlign="center" nzWidth="120px">账户类型</th>
          <th nzAlign="center" nzWidth="150px">收款账号</th>
          <th nzAlign="center" nzWidth="120px">收款人</th>
          <th nzAlign="center" nzWidth="170px">揽件时间</th>
          <th nzAlign="center" nzWidth="170px">到货签收时间</th>
          <th nzAlign="center" nzWidth="170px">成交时间</th>
          <th nzAlign="center" nzWidth="170px">更新时间</th>
          <th nzAlign="center" nzWidth="200px" nzRight>操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <td
            nzAlign="center"
            nzLeft
            [nzChecked]="setOfCheckedId.has(data.id)"
            (nzCheckedChange)="onItemChecked(data.id, $event)"
          ></td>
          <!-- 订单编号 -->
          <td nzAlign="center" nzLeft>{{ data.okey || '-' }}</td>

          <!-- 订单状态 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': orderStatusFilter(data.ostat, 'color')}">
              {{ orderStatusFilter(data.ostat, 'text') }}
            </span>
          </td>

          <!-- 退货信息 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': (data?.backI5addrid == '0' || !data?.backI5addrid) ? '#ff4d4f' : '#52c41a'}">
              {{ (data?.backI5addrid == '0' || !data?.backI5addrid) ? '无' : '有' }}
            </span>
          </td>

          <!-- 验机状态 -->
          <td nzAlign="center">{{ machineStatusFilter(data.checkStatus) }}</td>

          <!-- 下单机型 -->
          <td nzAlign="center">{{ data.umname || '-' }}</td>

          <!-- 预估合计 -->
          <td nzAlign="center">
            {{ (data.uprc || 0) + (data.orderAprc || 0) + (data.cprc || 0) }}
            <span *ngIf="data.orderAprc || data.cprc">（含加价{{ (data.orderAprc || 0) + (data.cprc || 0) }}）</span>
          </td>

          <!-- 机器编码 -->
          <td nzAlign="center" class="list-ptd">
            <ng-container *ngIf="data?.phoneCheckList?.length;else templateCode">
              <ng-container *ngFor="let item of data?.phoneCheckList">
                <p class="p-td">
                  <i nz-icon nzType="code" nzTheme="twotone" *ngIf="data?.phoneCheckList?.length > 1"></i>
                  {{ item.phoneCode || '-' }}
                </p>
              </ng-container>
            </ng-container>
            <ng-template #templateCode>-</ng-template>
          </td>

          <!-- 验机价 -->
          <td nzAlign="center" class="list-ptd">
            <ng-container *ngIf="data?.phoneCheckList?.length;else templatePice">
              <ng-container *ngFor="let item of data?.phoneCheckList">
                <p class="p-td">{{ item.price || '-' }}</p>
              </ng-container>
            </ng-container>
            <ng-template #templatePice>-</ng-template>
          </td>

          <!-- 加价金额 -->
          <td nzAlign="center" class="list-ptd">
            {{ data?.aprc || '-' }}
          </td>

          <!-- 下单抽奖 -->
          <td nzAlign="center" class="list-ptd">
            {{ data?.cprc || '-' }}
          </td>

          <!-- 验机合计 -->
          <td nzAlign="center">
            <ng-container *ngIf="data?.phoneCheckList?.length && data?.ostat !== 21;else templateyhj">
              <p [ngStyle]="{'color': ((data.bprc || 0) + (data.aprc || 0) + (data.cprc || 0)) < ((data.uprc || 0) + (data.orderAprc || 0) + (data.cprc || 0)) ? '#FF0000' : ''}">
                {{ (data.bprc || 0) + (data.aprc || 0) + (data.cprc || 0) }}
                <!-- <span *ngIf="data.aprc">（含加价{{ data.aprc }}）</span> -->
              </p>
            </ng-container>
            <ng-template #templateyhj>-</ng-template>
          </td>

          <!-- 下单时间 -->
          <td nzAlign="center">{{ data.otime11 || '-' }}</td>

          <!-- 账户类型 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.payway | accountTypeStatus: 'color'}">
              {{ data.payway | accountTypeStatus: 'label' }}
            </span>
          </td>

          <!-- 收款账号 -->
          <td nzAlign="center">{{ data.payacc || '-' }}</td>

          <!-- 收款人 -->
          <td nzAlign="center">{{ data.payname || '-' }}</td>

          <!-- 揽件时间 -->
          <td nzAlign="center">{{ data.otime13 || '-' }}</td>

          <!-- 到货签收时间 -->
          <td nzAlign="center">{{ data.otime14 || '-' }}</td>

          <!-- 成交时间 -->
          <td nzAlign="center">{{ data.otime19 || '-' }}</td>

          <!-- 更新时间 -->
          <td nzAlign="center">{{ data.updateTime || '-' }}</td>

          <!-- 操作 -->
          <td nzAlign="center" nzRight>
            <a
              nz-button
              nzType="link"
              target="_blank"
              [routerLink]="['/aisi-recyc/loveOrderDetails']"
              [queryParams]="{ id: data.id }">
              查看
            </a>
            <a nz-button nzType="link" (click)="followModal(data)">跟进订单</a>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ total }} 条</ng-template>
  </div>
</nz-card>

<!-- 跟进Component -->
<app-follow-up #followUpRef [initParams]="initParams" [ohterParams]="{ type: 1 }"></app-follow-up>

<!-- 打款失败 START -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [(nzVisible)]="isPaymentVisible"
  nzTitle="打款失败"
  (nzOnCancel)="isPaymentVisible = false">

  <div *nzModalContent>
    <div class="custom-model-body">
      <!-- body START -->
      <form nz-form class="form-modal-body" [formGroup]="paymentForm">
        <p class="payment-tips">是否确定要将订单改为打款失败状态？</p>
        <nz-form-item>
          <nz-form-label nzSpan="7" nzRequired>打款失败原因</nz-form-label>
          <nz-form-control nzSpan="17" nzErrorTip="请选择打款失败原因!">
            <nz-select
              nzShowSearch
              nzAllowClear
              nzPlaceHolder="请选择打款失败原因"
              formControlName="type"
              (ngModelChange)="reasonChange($event)">
              <nz-option
                *ngFor="let item of paymentReasons"
                [nzLabel]="item.label"
                [nzValue]="item.value">
              </nz-option>
            </nz-select>
          </nz-form-control>
        </nz-form-item>
      </form>
      <!-- body END -->
    </div>

    <div class="custom-model-foot">
      <div class="custom-foot-cont">
        <button nz-button nzType="primary" (click)="subPayment(0)">确定</button>
        <button nz-button nzType="default" (click)="isPaymentVisible = false">取消</button>
      </div>
    </div>
  </div>
</nz-modal>
<!-- 打款失败 END -->

